home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / games / 73 / pascal / joysubs.s < prev    next >
Text File  |  1986-11-21  |  2KB  |  72 lines

  1.         .xdef   INIT_STICK,END_STICK,STICK
  2.         .text
  3. *
  4. * Get the address of the keyboard packet handle table, and replace the joystick
  5. * handler.  Set up our own vector as the joystick handler
  6. INIT_STICK:
  7.         bsr     get_vectors
  8.         move.l  24(a0),a1       * Stick handler is at *a0[6]
  9.         move.l  a1,old_vec
  10.         move.l  #do_stick,24(a0)
  11.         move.w  #$12,d0         * Turn mouse off
  12.         bsr     send_cmd
  13.         move.w  #$15,d0         * And turn joystick on, interrogate mode
  14.         bsr     send_cmd
  15.         rts                     * Then return to caller
  16. *
  17. * Turn off joysticks, and turn on mouse.  Replace the old joystick packet
  18. * handler vector.
  19. END_STICK:
  20.         move.w  #$08,d0         * Turn off joysticks by turning on mouse
  21.         bsr     send_cmd
  22.         bsr     get_vectors     * Now replace old stick handler
  23.         move.l  old_vec,a1
  24.         move.l  a1,24(a0)
  25.         rts                     * Return to caller
  26. *
  27. get_vectors:
  28.         move.w  #34,-(sp)       * Get address of keyboard packet handler tbl
  29.         trap    #14
  30.         add.l   #2,sp
  31.         move.l  d0,a0
  32.         rts
  33. *
  34. send_cmd:
  35.         move.w  d0,-(sp)        * Just perform a bconout to the keyboard
  36.         move.w  #4,-(sp)
  37.         move.w  #3,-(sp)
  38.         trap    #13
  39.         add.l   #6,sp
  40.         rts
  41. *
  42. do_stick:
  43.         lea     stick0,a1       * Get a pointer to our data area in a1
  44.         move.b  (a0),d1         * Get direction bits
  45.         move.b  d1,(a1)         * and save in our data
  46.         move.b  1(a0),d1
  47.         move.b  d1,1(a1)
  48.         st      done
  49. notevent:
  50.         rts
  51. *
  52. STICK:
  53.         move.w  #$16,d0         * Interrogate joystick
  54.         clr.b   done
  55.         bsr     send_cmd
  56. wait:   tst.b   done
  57.         beq     wait
  58.         move.l  (sp)+,a0        * Save return address
  59.         move.w  (sp)+,d1        * get stick number (0-1)
  60.         and.w   #1,d1
  61.         lea     stick0,a1
  62.         move.b  (a1,d1.w),d0    * Return with our stick value as the fn. result
  63.         and.w   #$FF,d0
  64.         jmp     (a0)            * and return
  65. *
  66.         .bss
  67. old_vec:        .ds.l   1
  68. stick0:         .ds.b   1       * position for stick 0
  69. stick1:         .ds.b   1       * and stick 1
  70. done:           .ds.b   1
  71.         .end
  72.